//
//  LoginViewController.m
//  EcmDoctor
//
//  Created by 张进 on 15/7/2.
//  Copyright (c) 2015年 张进. All rights reserved.

#import "LoginViewController.h"
#import "AppUtils.h"
#import "DoctorIfo.h"

@interface LoginViewController ()

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.leftBarButtonItem.title = @"";
    self.navigationItem.titleView=[AppUtils generateNavigationItemTitleViewWithTitle:@"登录"];
    self.view.backgroundColor = [AppUtils getBackground];
    
    [self creatUI];
    
}

- (void)creatUI {
    //文本框的左视图
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _userName.frame.size.height+10, _userName.frame.size.height-1)];
    UIImageView *leftImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, _userName.frame.size.height-1, _userName.frame.size.height-2)];
    [view1 addSubview:leftImageView];
    leftImageView.image = [UIImage imageNamed:@"number"];
    _userName.leftView = view1;
    //设置显示模式
    _userName.leftViewMode = UITextFieldViewModeAlways;
    
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _userName.frame.size.height+10, _userName.frame.size.height-1)];
    
    UIImageView *leftImageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, _userName.frame.size.height-1, _userName.frame.size.height-2)];
    
    [view2 addSubview:leftImageView1];
    leftImageView1.image = [UIImage imageNamed:@"locked"];
    _password.leftView = view2;
    _password.leftViewMode = UITextFieldViewModeAlways;
    
    _password.leftView = view2;
    //设置显示模式
    _password.leftViewMode = UITextFieldViewModeAlways;
    
}

- (UIImage *)addImage:(UIImage *)image1 toImage:(UIImage *)image2 {
    UIGraphicsBeginImageContext(image1.size);
    
    // Draw image1
    [image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)];
    
    // Draw image2
    [image2 drawInRect:CGRectMake(0, 0, image2.size.width, image2.size.height)];
    
    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return resultingImage;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

-(IBAction)testClick:(id)sender {
    
    //    if (_userName.text != nil || ![_userName.text isEqualToString:@""]) {
    //        if (_userName.text.length != 11 || [_userName.text characterAtIndex:0] != '1') {
    //            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示：" message:@"请输入正确手机号" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    //            [alert show];
    //            return;
    //        }
    //    } else {
    //        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示：" message:@"请输入手机号" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    //        [alert show];
    //        return;
    //    }
    //
    //
    //    if (_password.text == nil || [_password.text isEqualToString:@""]) {
    //        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示：" message:@"请输入密码" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    //        [alert show];
    //        return;
    //    }
    
//    [DoctorIfo loginWithUsername:_userName.text Password:_password.text success:^(DoctorIfo *doctor) {
//        NSLog(@"%@", doctor);
    //    CATransition *animation = [CATransition animation];
    //    [animation setDuration:0.4];
    //    [animation setType: kCATransitionPush];
    //
    //    [animation setSubtype: kCATransitionFromBottom];
    //    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    //
    //    [self.navigationController.view.layer addAnimation:animation forKey:nil];
    //    [self.navigationController popViewControllerAnimated:NO];
//    } failure:^(NSError *error) {
//        NSLog(@"%@",error.localizedDescription);
//    }];
//    
//   18734837350  123456  18501363213    654321
    
    
//    _password.text=@"654321";
//    [[NSUserDefaults standardUserDefaults]setObject:_password.text forKey:APP_USERPASSWORD_KEY];
    
    [DoctorIfo loginWithUsername:@"18501363213" Password:@"654321" success:^(DoctorIfo *doctor) {
    
//    [DoctorIfo loginWithUsername:@"18734837350" Password:@"123456" success:^(DoctorIfo *doctor) {
    
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.4];
        [animation setType: kCATransitionPush];
        
        [animation setSubtype: kCATransitionFromBottom];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        
        [self.navigationController.view.layer addAnimation:animation forKey:nil];
        [self.navigationController popViewControllerAnimated:NO];
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error.localizedDescription);
        
    }];
    
    
}



//-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
//
//    if ([segue.identifier isEqualToString:@"segueLogin"]) {
//        id coll = segue.destinationViewController;
//    }
//    
//    
//    




@end
